

var getVideo = function (camName, ID,containID) {
    $.ajax({
        type: 'GET',
        url: 'https://wx.honghengxinxi.com:3033/vlc/vlcList',
        dataType: 'json',
        success: function (res) {
            axios.get('https://wx.honghengxinxi.com:3033/playUrl/video', {
                params: {
                    camName: camName,
                }
            })
                .then(function (res) {
                    playVideo(res.data, ID,containID)
                })
        }
    })
}

async function getListVideo(){
    
    return new Promise(function(resolve,reject){
        axios.get('https://wx.honghengxinxi.com:3033/vlc/vlcList?page=1&limit=40').then(
            res => {
                
                let arr=res.data.data.map(
                    function(item){
                        return item.camName
                    }
                )
                resolve(arr)
            }
        ).catch(
            err=>{
                reject(err)
            }
        )
    })


    
}
function playVideo(playurl, id,containID) {
    let body = document.getElementById(containID)
    let tree = `<div class="video" id="${id}" data-url='${playurl}'></div>`
    body.innerHTML += tree;
    var vUrl = $(`#${id}`).data('url');
    var videoObject = {
        container: `#${id}`,
        variable: 'player',
        live: true,
        autoplay: true,
        mobileCkControls: false,
        video: vUrl,
    };
    var player = new ckplayer(videoObject);
}

window.playNum=0
getListVideo().then(
    arr=>{
        $("#detail").empty();
        getVideo(arr[window.playNum], 'v2','detail');
        document.querySelector("#getBeforeVideo").onclick = function () {
                
            if(window.playNum > 0){
                window.playNum--;
                getListVideo().then(
                    arr=>{
                        $("#detail").empty();
                        getVideo(arr[window.playNum], 'v2','detail');
                    }
                );
            }
            else{
                window.playNum = 32
                getListVideo().then(
                    arr=>{
                        $("#detail").empty();
                        getVideo(arr[window.playNum], 'v2','detail');
                    }
                );
                // alert('已经是第一个了')
            }
        }
        document.querySelector("#getNextVideo").onclick = function () {
            if(window.playNum < 33){
                window.playNum++;
                getListVideo().then(
                    arr=>{
                        $("#detail").empty();
                        getVideo(arr[window.playNum], 'v2','detail');
                    }
                );
            }
            else{
                window.playNum=0
                getListVideo().then(
                    arr=>{
                        $("#detail").empty();
                        getVideo(arr[window.playNum], 'v2','detail');
                    }
                );
                // alert('已经是最后一个了')
            }
        
        }
    }
    
);
